var orderInfo = {
	orderNo : orderNo,
	busType : orderType
};

$(document).ready(function() {
//	if (PRDNAME === "提现") {
//		$(".out").css("display", "block");
//	} else if (PRDNAME === "充值" || PRDNAME === "收款") {
//		$(".in").css("display", "block");
//	} else if (PRDNAME === "消费") {
//		$(".in").css("display", "block");
//	}
	getOrderInfo();
});

/**
 * 获取订单信息
 */
function getOrderInfo() {
	// var form = getOrderForm();

	var data = $.extend({}, orderInfo);
	data['start'] = '0';
	data['pageSize'] = '1';
	// var data_t=$.extend({}, orderInfo_Type);
	$("#casBtn").hide();
	var url = BASE_PATH + "TR0001.web";
	formSubmitForAjax({
		url : url,
		data : data,
		success : function(json) {
			if (codeSuccess(json)) {
				try {
					var order = $.extend({}, orderInfo, json["tranList"][0]);
					console.log(order);
//					var ORDSTATUS = orderInfo['ordstatus'];
					showTable(order);
//					showCasBtn(order);
				} catch (e) {
					alert("订单信息查询失败！");
				}
			}
		}
	});
}

function showTable(order){
	$(".td-data", getOrderTable()).html("");
	var $box = $('.orderBox');
	$box.hide();
	
	var orderType = order['ordType'];
	//收款订单或商品订单
	if(orderType == '01' || orderType == '02'){
		$box = $('.prdOrdBox');
	}else if(orderType == '03'){
		$box = $('.casOrdBox');
	}
	// 填充表格
	fillTable($box, order);
	$box.show();
}

function getOrderTable() {
	return $(".orderBox");
}

function reLoad() {
	$(".td-data", getOrderTable()).html("");
	getOrderInfo();
}

function showCasBtn(order){
	var orderType = order['ordType'];
	//收款订单才有可能发起提现
	if(orderType != '01'){
		return;
	}
	//没有支付成功的订单不允许发起提现
	var ordstatus = order['ordstatus'];
	if(ordstatus != '01'){
		return;
	}
	var ordTime = order['ordtime'];
	if(!ordTime){
		return;
	}
	ordTime = ordTime.substring(0,8);
	var date = (new Date().Format("YYYYMMdd"));
	if(ordTime != date){//不是当天的交易,不允许发起T0(后台也会验证)
		return;
	}
	
	//提现状态不是未提现,不能发起T0
	var casstatus = order['casstatus'];
	if(casstatus != '00'){
		return;
	}
//	alert(ordTime+ "=" + date);
	//alert(Format("YYYYMMddHHmmss"));
	$("#casBtn").unbind("click").one("click",function(){
		casByOrder(order);
//		alert( $(this).text() );
	}).show();
}

function casByOrder(order){
	var r = confirm("您确定要发起T0提现申请吗！");
	if(!r){
		showCasBtn(order);
		return;
	}
	var data = {
		casType : '00',
		prdOrdNo : order['orderNo']	,	
		prdOrdNO : order['orderNo']		
	};
	formSubmitForAjax({
		url : 'CK0002.web',
		data : data,
		success : function(json) {
			alert(json['RSPMSG']);
		}
	});
}